package com.example.demo.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


//除了登录以外都要进行拦截
//重启服务器的什么情况回到登录流程
//重启浏览器的情况
@Configuration
public class MyMVCconfig implements WebMvcConfigurer {


    @Override
    public void addViewControllers(ViewControllerRegistry registry) {

        registry.addViewController("/login.html").setViewName("page/login");
        registry.addViewController("/").setViewName("page/login");
        registry.addViewController("/supermarket").setViewName("page/login");
        registry.addViewController("/Add").setViewName("page/userAdd");
    }

    @Autowired
    MyIntercepter myIntercepter;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        registry.addInterceptor(myIntercepter)
                .addPathPatterns("/**")
                .excludePathPatterns("/", "/login.html",
                                        "/supermarket",
                                        "/toLoginPage",
                                        "/toLogin",
                                        "/css/**",
                                        "/img/**",
                                        "/js/**");

    }
}
